class Admin::ShopersController < AdminController
  before_action :set_shop

  def index
    @shopers = @shop.shopers.order("created_at DESC").page(params[:page]).per(params[:per])
  end

  def new
    @shoper = Shoper.new
  end

  def create
    @shoper = @shop.shopers.build shoper_params
    if @shoper.save
      redirect_to admin_shop_shopers_path(@shop), notice: "保存成功！"
    else
      redirect_to admin_shop_shopers_path(@shop), notice: "保存失败！"
    end
  end

  def edit
    @shoper = Shoper.find params[:id]
  end

  def update
    @shoper = Shoper.find params[:id]
    if @shoper.update shoper_params
      redirect_to admin_shop_shopers_path(@shop), notice: "更新成功！"
    else
      redirect_to admin_shop_shopers_path(@shop), notice: "更新失败！"
    end
  end
  
  def destroy
    @shoper = Shoper.find params[:id]
    if @shoper.destroy
      redirect_to admin_shop_shopers_path(@shop), notice: "删除成功."
    else
      redirect_to admin_shop_shopers_path(@shop), notice: "删除失败."
    end
  end

  private

  def set_shop
    @shop = Shop.find params[:shop_id]
  end
  

  def shoper_params
    params.require(:shoper).permit(:name, :nickname, :password, :avatar, :phone)
  end
end
